package cn.weakup.thread.question._synchronized;

/**
 * @author Dawn
 * @version 1.0.0
 * @desc
 * @date 2022/5/10
 */
public class LockMethodBlock {
    public void method1(){
        System.out.println("Method 1 start");
        try {
            synchronized (this){
                System.out.println("Method 1 execute");
                Thread.sleep(3000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Method 1 end");
    }

    public void method2(){
        System.out.println("Method 2 start");
        try {
            synchronized (this) {
                System.out.println("Method 2 execute");
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Method 2 end");
    }
}
